package com.useeinfo.oa.open.admin.maintaining;

import com.alibaba.fastjson.JSONObject;
import com.useeinfo.framework.sugar.data.QueryParam;
import com.useeinfo.oa.modules.base.entity.Enterprise;
import com.useeinfo.oa.modules.maintaining.biz.AuditOrderBiz;
import com.useeinfo.oa.modules.security.util.SessionKeyUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/web/admin/auditOrder")
public class AuditOrderAction {

    @Autowired
    private AuditOrderBiz auditOrderBiz;

    @RequestMapping("/list")
    public ModelAndView list() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("pages/admin/auditOrder/list");
        return modelAndView;
    }

    @RequestMapping("/listJson")
    @ResponseBody
    public JSONObject listJson(@RequestParam(value = "pageNo", required = false) String pageNowParam,
                               @RequestParam(value = "pageSize", required = false) String pageSizeParam,
                               @RequestParam(value = "name", required = false) String name,
                               @RequestParam(value = "startTime", required = false) String startTimeParam,
                               @RequestParam(value = "endTime", required = false) String endTimeParam,
                               HttpServletRequest request) {
        QueryParam queryParam = new QueryParam(pageNowParam, pageSizeParam);
        queryParam.getSqlMap().put("name",name);
        queryParam.getSqlMap().put("startTime",startTimeParam);
        queryParam.getSqlMap().put("endTime",endTimeParam);
        Enterprise enterprise = SessionKeyUtils.getSessionEnterprise(request);
        if(enterprise!=null){
            queryParam.getSqlMap().put("enterpriseId", enterprise.getId()+"");
        }
        return auditOrderBiz.findJSONList(queryParam);
    }


}
